<?php
include 'conn_mysql.php';







$id_fu=$_REQUEST['id_fu'];
//查询用户信息
$sql="select * from fu_user where id_fu='".$id_fu."'";
$query = mysql_query($sql);
while($row = mysql_fetch_array($query)){
	$id_fu=$row['id_fu'];
	$name=$row['name'];
	$phone=$row['phone'];
	$idcode=$row['idcode'];
	$choose=$row['choose'];
	$id=$row['id'];
}

?>
<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, maximum-scale=1, user-scalable=no">
    <title>驴行天下</title>
    <link href="bootstrap.min.css" rel="stylesheet">
    <link href="style.css" rel="stylesheet" type="text/css">
	<script language="javascript" src="js/jquery.min182.js"></script>
	<script language="javascript" src="js/jquery.form.js"></script>
	<script language="javascript" src="js/json.parse.js"></script>
    <script type="text/javascript" src="js/jquery.js"></script>
</head>
<body>

	<?php
		//查看订单是否已取消或已支付
		if($id_main)
		{
			$sql="select id_self,is_zhifu from main_user where id_self='$id_main' ";
			$query = mysql_query($sql);
			while($row = mysql_fetch_array($query)){
				$this_id_self=$row['id_self'];
				$is_zhifu=$row['is_zhifu'];
			}
			if(!$this_id_self)
			{
				echo "<SCRIPT>alert('订单不存在');window.history.go(-1);</SCRIPT>";
				exit;
			}

			if($is_zhifu>0)
			{
				echo "<SCRIPT>alert('订单已支付或已取消无法添加游客');window.history.go(-1);</SCRIPT>";
				exit;
			}
		}


	?>
<!--header-->
<div class="header_title">
	<!--<p>【贵州精华】2016全年贵州：西江千户苗寨-朗德上寨-荔波小七孔-黄果树瀑布-青岩古镇，奇山秀水、苗家风情之旅6日团</p>-->
	<p><?php echo $biaoti;?></p><!--旅游项目标题-->
</div>
<!--plate-->
<div class="plate">
	<h1>同行游客信息</h1>
    <div class="plate_line">
    	<div class="plate_line_name">姓&nbsp;&nbsp;&nbsp;&nbsp;名：</div>
        <div class="plate_line_input">
        	<input type="text" placeholder="请填写真实姓名" onfocus="if(placeholder=='请填写真实姓名') {placeholder=''}" onblur="if (placeholder=='') {placeholder='请填写真实姓名'}" id="name" value="<?php echo $name;?>">
        </div>
    </div>
    <div class="plate_line">
    	<div class="plate_line_name">手机号：</div>
        <div class="plate_line_input">
        	<input type="number" maxlength="11" id="phone" name="phone" onkeypress="intOnly()" style="ime-mode:Disabled" value="<?php echo $phone;?>"/>
        </div>
    </div>
    <div class="plate_line">
    	<div class="plate_line_name">身份证：</div>
        <div class="plate_line_input" id="id">
        	<input type="text" maxlength="18" id="idcode" name="id" style="ime-mode:Disabled" value="<?php echo $idcode;?>">
        </div>
    </div>
    <div class="plate_line">
        <div class="plate_line_choose">
        	<label><input type="radio" value="1" id="choose" name="choose"><p>成人(男)</p></label>
            <label><input type="radio" value="2" id="choose" name="choose"><p>成人(女)</p></label>
            <label><input type="radio" value="3" id="choose" name="choose"><p style="margin-right:0">儿童</p></label>
        </div>
    </div>
    
</div>
<?php if(strlen($id_fu)==0){?>
	<a class="button" style="margin-bottom:10px" onclick="tianjiayouke();"><input type="submit" value="添加游客"></a>
<?php }else{?>
	<a class="button" style="margin-bottom:10px" onclick="tianjiayouke();"><input type="submit" value="修改游客"></a>
<?php } ?>	

</body>
<script>
function intOnly(){
  var codeNum=event.keyCode;
  if(codeNum==8||codeNum==37||codeNum==39||(codeNum>=48&&codeNum<=57)){
    event.returnValue=codeNum;
  }else{
    event.returnValue=false;
  }
}
 function IdentityCodeValid(code) { 
            var city={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江 ",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北 ",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏 ",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外 "};
            var tip = "";
            var pass= true;
            
            if(!code || code.length!=18){
                tip = "身份证号格式错误";
                pass = false;
            }
            
           else if(!city[code.substr(0,2)]){
                tip = "地址编码错误";
                pass = false;
            }
            else{
                //18位身份证需要验证最后一位校验位
                if(code.length == 18){
                    code = code.split('');
                    //∑(ai×Wi)(mod 11)
                    //加权因子
                    var factor = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ];
                    //校验位
                    var parity = [ 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 ];
                    var sum = 0;
                    var ai = 0;
                    var wi = 0;
                    for (var i = 0; i < 17; i++)
                    {
                        ai = code[i];
                        wi = factor[i];
                        sum += ai * wi;
                    }
                    var last = parity[sum % 11];
                    if(parity[sum % 11] != code[17]){
                        tip = "校验位错误";
                        pass =false;
                    }
                }
            }
            if(!pass) alert(tip);
            return pass;
        }
//添加游客
function tianjiayouke(){
	var name      =      document.getElementById("name").value;
	var phone     =      document.getElementById("phone").value;
	var idcode    =      document.getElementById("idcode").value;
	var radios    =      document.getElementsByName("choose");
	var choose=0;
	for ( var i = 0; i < radios.length; i++) {
	    if (radios[i].checked==true) {
		    i++;
	        if(i==1){
				choose=1;
			}
			if(i==2){
				choose=2;
			}
			if(i==3){
				choose=3;
			}
	    }
	}

	
	
	//参数非空控制
	if(name == "" || name == undefined || name == null){
		alert("姓名不允许为空！");
		return 0;
	}
	if(phone == "" || phone == undefined || phone == null){
		alert("手机号不允许为空！");
		return 0;
	}

	var reg = /^0?1[3|4|5|8][0-9]\d{8}$/;
	 if (!reg.test(phone)) {
	      alert("手机号格式不正确~");
	      return 0;
	 }

	if(idcode == "" || idcode == undefined || idcode == null){
		alert("身份证号不允许为空！");
		return 0;
	}
	var id_status=IdentityCodeValid(idcode);
	if(!id_status){return false;}

	if(!choose)
	{
	    alert("请选择性别");
		return 0;	
	}
	var url="getmessage_all.php?bigtype=2";
	url=url+"&id_fu=<?php echo $_REQUEST['id_fu'];?>";
	url=url+"&id=<?php echo $_REQUEST['id'];?>";
	url=url+"&name="+name;
	url=url+"&phone="+phone;
	url=url+"&idcode="+idcode;
	url=url+"&choose="+choose;

	$.ajax({
		type:"GET",
		url:url,
		dataType: "json",
		success: function(data){	
			if(data['code']==0001){
				//alert("数据成功上传！");
				window.location.href='index_pay.php';
			}else{
				
			}
		},
		error:function(){
			alert("123");
		}
	});
	
}
//跳转到添加游客页面
function tianjiayouke1(){
	window.location.href='add.php?id=<?php echo $_REQUEST['id'];?>';
}
function jinglaijiukais(){
	var radio_oj = document.getElementsByName("choose");
	for(var i=0;i<radio_oj.length;i++) {//循环
        if(radio_oj[i].value=="<?php echo $choose;?>"){  //比较值
            radio_oj[i].checked=true; //修改选中状态
            break; //停止循环
        }
    }
}
window.onload=jinglaijiukais;
</script>
</html>
